using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Castle.ActiveRecord;

/// <summary>
/// Summary description for FileType
/// </summary>
/// 

[ActiveRecord]
public class FileType : ActiveRecordBase<FileType>
{
    public static NHibernate.Expression.MatchMode Exact = NHibernate.Expression.MatchMode.Exact;
    public static NHibernate.Expression.MatchMode Anywhere = NHibernate.Expression.MatchMode.Anywhere;
    public static NHibernate.Expression.MatchMode End = NHibernate.Expression.MatchMode.End;
    public static NHibernate.Expression.MatchMode Start = NHibernate.Expression.MatchMode.Start;

    private int fileTypeID;

    [PrimaryKey(PrimaryKeyType.Identity)]
    public int FileTypeID
    {
      get { return fileTypeID; }
      set { fileTypeID = value; }
    }

    private String caption;

    [Property]
    public String Caption
    {
      get { return caption; }
      set { caption = value; }
    }
    private String description;

    [Property]
    public String Description
    {
      get { return description; }
      set { description = value; }
    }

    private bool activeFlag;

    [Property]
    public bool ActiveFlag
    {
        get { return activeFlag; }
        set { activeFlag = value; }
    }

    private DateTime createdDate;

    [Property]
    public DateTime CreatedDate
    {
        get { return createdDate; }
        set { createdDate = value; }
    }

    private DateTime updatedDate;
    [Property]
    public DateTime UpdatedDate
    {
        get { return updatedDate; }
        set { updatedDate = value; }
    }

    private String createdBy;
    [Property]
    public String CreatedBy
    {
        get { return createdBy; }
        set { createdBy = value; }
    }


    private String updatedBy;

    [Property]
    public String UpdatedBy
    {
        get { return updatedBy; }
        set { updatedBy = value; }
    }

	public FileType()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public FileType(String caption,String description,bool active,String createdBy)
    {
        this.caption = caption;
        this.description = description;
        this.activeFlag = active;
        this.createdBy = createdBy;
        this.updatedBy = createdBy;
        this.createdDate = DateTime.Now;
        this.updatedDate = DateTime.Now;
    }

    public static void add_filetype(String caption,String description, bool active, String createdBy)
    {
        FileType filetype = new FileType(caption,description,active,createdBy);
        filetype.Create();
    }

    public static void edit_filetype(int filetypeID, String caption,String description, String updatedBy)
    {
        FileType filetype = get_filetype(filetypeID);
        filetype.caption = caption;
        filetype.description = description;
        filetype.updatedBy = updatedBy;
        filetype.updatedDate = DateTime.Now;
        filetype.Update();        
    }

    public static void edit_filetype(int filetypeID,bool active,String updatedBy)
    {
        FileType filetype = get_filetype(filetypeID);
        filetype.activeFlag = active;
        filetype.updatedBy = updatedBy;
    }

    public static void delete_filetype(int filetypeID)
    {
        FileType filetype = get_filetype(filetypeID);
        filetype.Delete();
    }

    public static FileType get_filetype(int filetypeID)
    {
        return FindByPrimaryKey(filetypeID);
    }

    public static FileType[] get_all_filetype()
    {
        return FindAll();
    }

    public static int count_all_filetype()
    {
        return Count();
    }

    public static FileType[] search_filetype(String propertyName, String textSearch, NHibernate.Expression.MatchMode mode)
    {
        NHibernate.Expression.DetachedCriteria criteria = NHibernate.Expression.DetachedCriteria.For<FileType>();

        criteria.Add(NHibernate.Expression.Expression.InsensitiveLike(propertyName, textSearch, mode));

        return FindAll(criteria, FileType.Asc(propertyName));
    }

    public static FileType[] get_filetype_and_sort(String propertyName, String order)
    {
        NHibernate.Expression.DetachedCriteria avgWeight = NHibernate.Expression.DetachedCriteria.For<FileType>();
        if (order == "ASC")
            return FindAll(avgWeight, Asc(propertyName));
        return FindAll(avgWeight, Desc(propertyName));
    }

}
